<%
response.reset();
response.setContentType("application/octet-stream");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition","attachment;filename=\"userlist.xls\"" ); 
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  
import="java.util.*,java.text.SimpleDateFormat,
com.brother.model.*,com.ibatis.common.util.PaginatedList
,com.brother.util.DateFormatter,com.brother.model.AlarmType,
java.util.*,
com.brother.model.*,com.ibatis.common.util.*,com.brother.util.Distance,com.brother.service.*,com.brother.util.MyPaginatedList"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="international.jsp" %> 
<jsp:useBean id="userService" class="com.brother.service.UserService"></jsp:useBean>
<%

com.brother.model.Customer loginUser = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
if(loginUser ==null){
	return;
}
int start = Integer.parseInt(request.getParameter("start")==null?"0":request.getParameter("start"));
int limit = Integer.parseInt(request.getParameter("limit")==null?"20":request.getParameter("limit"));
String action = request.getParameter("action");
if(action != null && action.equalsIgnoreCase("delete")){
	String[] userids = request.getParameterValues("userid");
	for(String userid : userids){
		if(!userid.equals(loginUser.getUserid()))
			userService.deleteUser(loginUser, Integer.parseInt(userid));
	}
	response.sendRedirect("userList.jsp");
}

String userName = request.getParameter("userName");
if(userName != null) userName = userName.trim();
if(userName != null && userName.startsWith("Select")){
	userName = null;
}

List<Customer> users = userService.getChildUsers(loginUser.getUserid(), userName);
System.out.println(userName);
if(userName == null || userName.isEmpty() || loginUser.getName().startsWith(userName))
users.add(0, userService.GetUserByUserId(loginUser.getUserid()));

Iterator<Customer> datas = users.iterator();


%>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title><fmt:message key="report.title"/> - <fmt:message key="company.name"/></title>
<meta name="description" content="<fmt:message key="description.keyword"/>" />
</head>
<body>

<table  width="100%" cellpadding="5" cellspacing="0"  border="1">
		<thead>		
	<tr>
		<th width="100"><strong><fmt:message key="user.name"/></strong></th>
		<th width="180"><strong><fmt:message key="user.email"/></strong></th>
		<th width="180"><strong><fmt:message key="user.supervisor"/></strong></th>
		<th width="100"><strong><fmt:message key="user.admin"/></strong></th>
		<th width="250"><strong><fmt:message key="user.description"/></strong></th>
	</tr>
</thead>

<%
int count = 0;

while(datas.hasNext()){
	Customer customer = datas.next();	
	count++;
	Customer sup = userService.getSuperiorUser(customer.getUserid()+"");
	
%>

		<tr bordercolor="#cccccc">
			<td style=" font-size:11px;"><b><%=customer.getName()%>&nbsp;</b></td>
			<td style=" font-size:11px;"><%=customer.getEmail()%>&nbsp;</td>
			<td style=" font-size:11px;"><%=sup == null ? "":sup.getName()%>&nbsp;</td>
			<td style=" font-size:11px;"><%if(customer.isAdmin()){%><fmt:message key="user.admin.yes"/><%}else{ %><fmt:message key="user.admin.no"/><%} %>&nbsp;</td>
			<td style=" font-size:11px;"><%=customer.getDescription()%>&nbsp;</td>
		</tr>
 
<%} %>
	
		</table>



</body>
</html>
					  
<%
com.brother.database.DataBase.closeThreadConnection();
%>